﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeBuilder2.DAL.Schema;
using System.Data;

namespace CodeBuilder2.BLL.Schema
{
    class ServerBLL
    {
        ServerDAL sDal = new ServerDAL();

        /// <summary>
        /// 获取指定服务器下存在的全部数据库的名称，没有则返回 null
        /// </summary>
        /// <param name="serverName">要在其上获取数据库名的服务器名称</param>
        /// <returns></returns>
        internal List<string> GetDataBasesName(string serverName)
        {
            DataTable dt = sDal.GetSysDataBases(serverName);
            if (dt == null)
                return null;
            
            var names = from name in dt.AsEnumerable()
                        select new { name = name["database_name"].ToString() };
            //List<string> dbsName = new List<string>(names.Count()); // 得到的 Count 是 0，有问题
            List<string> dbsName = new List<string>();
            foreach (var item in names)
            {
                dbsName.Add(item.name);
            }
            return dbsName;
        }        
    }
}
